/*
 *  dna_devicecmd.h -- provide dna-system device special command management.
 *  
 *  ORIGINAL AUTHOR: Xu Chun (chun.xu@broadlink.com.cn)
 *
 *  Copyright (c) 2016 Broadlink Corporation
 */

#ifndef __DNA_DEVICECMD_H
#define __DNA_DEVICECMD_H

#include "dna_sdkconfig.h"

/*
*  The command code organization:
*
*  1) one-to-one correspondence
*       [Req UPLINK]          0 - 99             (   0 - 9     : system reserved, not change)
*       [Rsp DOWNLINK] 100 - 199            (100 - 109 : system reserved, not change)
*
*  2) single
*       [active DOWNLINK] >= 200            (200 - 209: system reserved, not change)
*/

#define DNA_DEVICE_CMD_STRUCT_MAXSIZE               260
#define DNA_DEVICE_UPLINK_CMD_BASE                  0
#define DNA_DEVICE_DOWNLINK_CMD_BASE                100
#define DNA_DEVICE_SINGLE_CMD_BASE                  200

#define DNA_DEVICE_UPLINK_CMD_CUSTOM_BASE           10
#define DNA_DEVICE_DOWNLINK_CMD_CUSTOM_BASE         110
#define DNA_DEVICE_SINGLE_CMD_CUSTOM_BASE           210

/*
*   dna-system reserved command code.
*/

/* 
*  dna-system now support uplink special command (Device -> WiFi module) type code.
*/
typedef enum {
    DNA_DEVICE_ACTIVE_UPLOAD = DNA_DEVICE_UPLINK_CMD_BASE,    /*!< uplink data: dna_devcmd_upload_req_t */
    DNA_DEVICE_GET_MODULE_TIME,                               /*!< uplink data: NULL */
    DNA_DEVICE_GET_MODULE_FIRMWARE_INFO,                      /*!< uplink data: NULL */
    DNA_DEVICE_RESET_MODULE,                                  /*!< uplink data: NULL */
    DNA_DEVICE_RETEST_MODULE,                                 /*!< uplink data: NULL */
    DNA_DEVICE_TO_MODULE_HB,                                  /*!< uplink data: NULL */
    DNA_DEVICE_FORMAT_MODULE,                                 /*!< uplink data: NULL */
    DNA_DEVICE_GET_MAC,
    DNA_DEVICE_AP_MODULE_REQ,
    DNA_DEVICE_GET_MODULE_WLAN_INFO,  
    DNA_DEVICE_FC_AUTOJOIN_REQ,						

} dna_device_uplink_cmd_e;

/* 
*  dna-system now support downlink special command (WiFi module -> Device) type code.
*/
typedef enum {
    /* Corresponding uplink command */
    DNA_MODULE_ACTIVE_UPLOAD_RES = DNA_DEVICE_DOWNLINK_CMD_BASE,  /*!< downlink data: NULL */
    DNA_MODULE_GET_TIME_RES,                                      /*!< downlink data: dna_devcmd_time_res_t */
    DNA_MODULE_GET_FIRMWARE_INFO_RES,                             /*!< downlink data: dna_devcmd_firmware_res_t */
    DNA_MODULE_RESET_RES,                                         /*!< downlink data: NULL */
    DNA_MODULE_RETEST_RES,                                        /*!< downlink data: NULL */
    DNA_MODULE_DEVICE_HB_RES,                                     /*!< downlink data: NULL */
    DNA_MODULE_FORMAT_RES,                                        /*!< downlink data: NULL */
    DNA_MODULE_GET_MAC_RES,
    DNA_MODULE_AP_DEVICE_RES,
    DNA_MODULE_GET_WLAN_INFO_RES,  
    DNA_MODULE_FC_AUTOJOIN_RES,

    /* Single command */
    DNA_MODULE_WIFI_CONFIG = DNA_DEVICE_SINGLE_CMD_BASE,          /*!< downlink data: NULL */
    DNA_MODULE_WIFI_CONNECTING,                                   /*!< downlink data: NULL */
    DNA_MODULE_WIFI_LINK,                                         /*!< downlink data: NULL */
    DNA_MODULE_CLOUD_LINK,                                        /*!< downlink data: NULL */
    DNA_MODULE_QUERY_DEVICE_STATUS,                               /*!< downlink data: NULL */
    DNA_MODULE_AIRCFG_DONE_NOTICE,                                /*!< downlink data: NULL */
} dna_device_downlink_cmd_e;

/*
*  DNA_DEVICE_ACTIVE_UPLOAD:
*
*  Special command data structure define.
*/
typedef struct dna_devcmd_upload_req {
    unsigned short len;
    /*!< Status upload: data section same as status query response packet */
    unsigned short is_status : 1;
    /*!< Fault upload */
    unsigned short is_fault  : 1;
    unsigned char data[DNA_DEVICE_FRAMEBUFFER_SIZE];
} dna_devcmd_upload_req_t;

/*
*  DNA_MODULE_GET_TIME_RES:
*
*  Special command data structure define.
*/
typedef struct dna_devcmd_time_res {
    unsigned short year;
    unsigned char second;
    unsigned char minute;
    unsigned char hour;
    unsigned char weekday;
    unsigned char day;
    unsigned char month;
} dna_devcmd_time_res_t;

/*
*  DNA_MODULE_GET_FIRMWARE_INFO_RES:
*
*  Special command data structure define.
*/
typedef struct dna_devcmd_firmware_res {
    unsigned short devtype;
    unsigned short firmware_version;
    unsigned short profile_version;
    unsigned short svn_version;
} dna_devcmd_firmware_res_t;

/*
*  DNA_MODULE_GET_MAC_RES:
*
*  Special command data structure define.
*/
typedef struct dna_devcmd_mac_res {
    unsigned char value[6];
} dna_devcmd_mac_res_t;


/*
*  DNA_MODULE_GET_WLANINFO_RES:
*
*  Special command data structure define.
*/
typedef struct dna_devcmd_wlan_res {
	unsigned char ssid[33];
	unsigned char psk[65];
	unsigned char bssid[6];
	unsigned char channel;
	signed char   rssi;
}dna_devcmd_wlan_res_t;	
#endif

